
from game.gui.menu import RadialMenu
import pygame
from pygame.locals import *

from game.gui.container import Container
from game.gui.game_area import GameArea


from game.equipment_manager import EquipmentManager
from game.inventory_manager import InventoryManager
from game.message_manager import MessageManager

"""
The layout of the GUI is:
----------------------------------
|                       |        |
|                       |        |
|                       |        |
|      game area        |  side  |
|                       |        |
|                       |        |
|                       |        |
------------------------|        |
|                       |        |
|      messages         |        |
|                       |        |
----------------------------------

"""
class GuiManager:
    def __init__(self, data):

        self.data = data

        #This is the width of the side bar, fixed width
        self.sidebar_width = 300

        #This is the height of the message bar, fixed height
        self.message_height = 120

        self.game_area = GameArea(data)
        self.msg_mgr = MessageManager(Rect(0, self.game_area.view_rect.height,
            self.game_area.view_rect.width, self.message_height))
        self.equ_mgr = EquipmentManager(Rect(0,0,self.sidebar_width, 200))
        self.inv_mgr = InventoryManager(Rect(0,200,self.sidebar_width, 400))


        #The full size of the window
        self.window_rect = pygame.Rect(0,0,
            self.game_area.view_rect.width + self.sidebar_width,
            self.game_area.view_rect.height + self.message_height)

        self.screen = pygame.display.set_mode(
            (self.window_rect[2], self.window_rect[3]))

        self.root = Container(rect=self.window_rect)
        self.side = Container(rect=Rect(
            self.game_area.view_rect.width, 0,
            self.sidebar_width, self.window_rect.height))

        self.root.add_child(self.side)
        self.root.add_child(self.game_area)

        self.root.add_child(self.msg_mgr.widget)
        self.side.add_child(self.equ_mgr.widget)
        self.side.add_child(self.inv_mgr.widget)

        self.icons = []


    def event(self, evt):
        self.root.receive(self.data, evt)

    def create_radial_menu(self, origin, size):
        x, y = origin[0] - (size[0] // 2), origin[1] - (size[1] // 2)
        menu = RadialMenu(rect=Rect(x,y,size[0],size[1]))
        return menu